package com.rx.substation.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.rx.substation.util.GetMonthUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.rx.substation.service.MonthRunUnitQCService;
/**
 * 站点周报，月报，半年报，年报，工作完成情况
 * @author dcx
 *
 */
@RestController
@RequestMapping(value = "/monthRunUnitQC")
public class MonthRunUnitQCController {

	@Autowired
	MonthRunUnitQCService monthRunUnitQCService;
	
//	@RequestMapping(value="/findall")
//	public List<Map<String,Object>> findMonthValidateDays(String start,String end){
//
//		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//		sdf.setTimeZone(TimeZone.getTimeZone("GMT+8"));
//        Calendar cal = Calendar.getInstance();
//        //获得上个月月初
//    	cal.add(Calendar.MONTH, -1);
//	    cal.set(Calendar.DATE, 1);
//	    start = sdf.format(cal.getTime());
//	    //获得上个月月末
//	    Calendar cal2 = Calendar.getInstance();
//	    cal2.add(Calendar.MONTH, -1);
//	    cal2.set(Calendar.DATE,cal2.getActualMaximum(Calendar.DAY_OF_MONTH));
//	    end = sdf.format(cal2.getTime());
//
//		return monthRunUnitQCService.getAllMonthQC(start,end);
//		return monthRunUnitQCService.getMonthQC(start,end);
//	}
	
	@RequestMapping(value="/findByConditions")
	public List<Map<String,Object>> findRunUnitQcByConditions(HttpServletRequest httpServletRequest){
		String status = httpServletRequest.getParameter("status");
		String[] runUnitIds =  httpServletRequest.getParameterValues("runUnitIds");
		String[] cityIds = httpServletRequest.getParameterValues("cityIds");
		String datestart = httpServletRequest.getParameter("start");
		String dateend = httpServletRequest.getParameter("end");
		String start = null;
		String end = null;
		try {
			start = GetMonthUtil.getFirstDay(datestart);
			end = GetMonthUtil.getLastDay(dateend);
		}catch (Exception e){
			e.printStackTrace();
		}
		String[] stationCodes = httpServletRequest.getParameterValues("stationCodes");
		return monthRunUnitQCService.findRunUnitQcByConditions(runUnitIds,cityIds,start,end,stationCodes,status);
	}
	
}
